<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use app\admin\controller\Base;
class Attr extends Base
{
    public function attribute()
    {	
    	header("content-type:text/html;charset=utf-8");
    	$cat_id = input("get.cat_id");
    	if(empty($cat_id)){

    		$where = array();
    	}else{

    		$where = array('attribute.cat_id'=>$cat_id);
    	}
    	$list = Db("attribute")->alias('a')->join("goods_type g","a.cat_id=g.cat_id")->where($where)->select();
    		foreach ($list as $key => $value) {
    			
    			$list[$key]['attr_values'] = str_replace("\r\n",",",$value['attr_values']);
    		}
    	
    	$datas = Db("goods_type")->select();
    	// echo "</pre>";
    	// print_r($data);die;
    	$this->assign("datas",$datas);
    	$this->assign("list",$list);
        return $this->fetch();
    }

    public function addattr()
    {	

    	header("content-type:text/html;charset=utf-8");
    	$data = Db("goods_type")->select();
    	// echo "</pre>";
    	// print_r($data);die;
    	$this->assign("data",$data);
        return $this->fetch();
    }

     public function addattrto()
    {	

    	header("content-type:text/html;charset=utf-8");
    	$data = input("post.");

    	$res = Db("attribute")->insert($data);
    	
    	if($res){

    		$this->success('添加成功',"attr/attribute");
    	}else{

    		$this->error('添加失败',"attr/addattr");
    	}
    }

}